package com.heima.wemedia.controller;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.wemedia.dtos.WmMaterialDto;
import com.heima.model.wemedia.entity.WmMaterial;
import com.heima.wemedia.service.WmMaterialService;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Update;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/v1/material")
public class MaterialController {

    @Resource
    private WmMaterialService wmMaterialService;

    @PostMapping("/upload_picture")
    public ResponseResult uploadPicture(MultipartFile multipartFile){
        return wmMaterialService.uploadPicture(multipartFile);
    }

    @PostMapping("/list")
    public ResponseResult list(@RequestBody WmMaterialDto wmMaterialDto){
        return wmMaterialService.findlist(wmMaterialDto);
    }

    @DeleteMapping("/del_picture/{id}")
    public ResponseResult delteMaterial(@PathVariable Integer id){

        //校验数据
        return wmMaterialService.deleteMaterial(id);
    }
    @PutMapping("/collect/{id}")
    public ResponseResult collectMaterial(@PathVariable Integer id){
        return wmMaterialService.updateMaterial(id);
    }

    @PutMapping("/cancel_collect/{id}")
    public ResponseResult cancelMaterial(@PathVariable Integer id){
        return wmMaterialService.updateMaterial(id);
    }

}
